/**
 * Creat with IntelliJ IDEA
 * Description:Thread的子类创建线程
 * User:WZW
 * Date:2021-11-26
 * Time:20:59
 */
class Left extends Thread
{
    int n = 0;
    public void run()
    {
        while(true)
        {
            n++;
            System.out.printf("\n%s","Left");
            try
            {
                sleep((int)(Math.random()*1000)+1000);
            }
            catch(InterruptedException e) {}
        }
    }
}

class Right extends Thread
{
    int n = 0;
    public void run()
    {
        while(true)
        {
            n++;
            System.out.printf("\n%40s","Right");
            try
            {
                sleep((int)(Math.random()*1000)+1000);
            }
            catch(InterruptedException e){}
        }
    }
}

public class Example8_3 {
    public static void main(String args[])
    {
        Left left = new Left();
        Right right = new Right();
        left.start();
        right.start();
        while(true)
        {
            System.out.println(left.n + "," + right.n);
            if(left.n>=8 || right.n>=8)
                System.exit(0);
        }
    }

}
